import 'package:fashion_app/config/app.dart';
import 'package:flutter/material.dart';

class RecomdCard extends StatelessWidget {
  final String title;
  final VoidCallback? onTap;
  final String bg;
  final String subTitle;
  final String? recomdImg;
  final String? goicon;
  final String? gotext;

  const RecomdCard({
    Key? key,
    required this.bg,
    required this.title,
    required this.subTitle,
    this.onTap,
    this.recomdImg,
    this.goicon,
    this.gotext,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: GestureDetector(
        onTap: onTap,
        child: Container(
          width: 164,
          height: 124,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20),
            color: AppConfig.themeColor.withOpacity(0.1),
          ),
          child: Container(
            padding: EdgeInsets.all(16),
            alignment: Alignment.center,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                // 第一个盒子
                Container(
                  child: Row(
                    children: [
                      // 设置一个56*56的图片
                      Image.asset(
                        recomdImg ?? '',
                        width: 56,
                        height: 56,
                        fit: BoxFit.cover,
                      ),
                      const SizedBox(width: 12),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            title,
                            style: TextStyle(
                              color: const Color(0xFF333333),
                              fontSize: 14,
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                          Text(
                            subTitle,
                            style: TextStyle(
                              color: const Color(0xFF999999),
                              fontSize: 12,
                              fontWeight: FontWeight.w400,
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
                const SizedBox(height: 12),
                // 第二个盒子
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        gotext ?? '',
                        style: TextStyle(
                          color: const Color(0xFF999999),
                          fontSize: 12,
                          fontWeight: FontWeight.w400,
                        ),
                      ),
                      Image.asset(
                        goicon ?? '',
                        width: 24,
                        height: 24,
                        fit: BoxFit.cover,
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class RecomdCardArea extends StatelessWidget {
  final List<Map<String, dynamic>> recomdList;
  const RecomdCardArea({Key? key, required this.recomdList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 修正上边距为16
    const marginTop = 10.0;
    const spacingWidth = 16.0;
    return Column(
      children: [
        Container(
          margin: EdgeInsets.only(top: marginTop),
          child: Row(
            children: recomdList
                .asMap()
                .entries
                .map((entry) {
                  final index = entry.key;
                  final item = entry.value;

                  return [
                    RecomdCard(
                      bg: item['bg'],
                      title: item['title'],
                      subTitle: item['subTitle'],
                      recomdImg: item['recomdImg'],
                      goicon: item['goicon'],
                      gotext: item['gotext'],
                      onTap: () {
                        // 跳转
                        print(item['jumpRoute']);
                      },
                    ),
                    if (index < recomdList.length - 1)
                      const SizedBox(width: spacingWidth),
                  ];
                })
                .expand((element) => element)
                .toList(),
          ),
        ),
      ],
    );
  }
}
